<script>
	export default {
		globalData: {
			 videoAd: tt.createRewardedVideoAd({
					adUnitId: "3jbb82ed91j92bu21n",
				}),
			currentPage: Object,
			
			playAd: function() {
				// 照抄的官方例子
				 const videoAd= tt.createRewardedVideoAd({
					adUnitId: "3jbb82ed91j92bu21n",
				})
				videoAd
					.show()
					.then(() => {
						console.log("广告显示成功");
					})
					.catch((err) => {
						console.log("广告组件出现问题", err);
						// 可以手动加载一次
						videoAd.load().then(() => {
							console.log("手动加载成功");
							// 加载成功后需要再显示广告
							return videoAd.show();
						});
					});
			},
	
		},
		onLaunch: function() {
			if (this.globalData.videoAd) {
				// onClose只监听一次
				this.globalData.videoAd.onClose(res => {
					if (res.isEnded) {
						// 实现子子页面的closeAdFunction与cancelAdFunction方法
						this.globalData.currentPage.closeAdFunction()
					} else {
						this.globalData.currentPage.cancelAdFunction()
					}
				})
			}
		},

		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";
	/*每个页面公共css */
</style>
